package bcontractor.builders.api;

import java.util.Collection;

import bcontractor.api.Sentence;
import bcontractor.api.SentenceSet;
import bcontractor.base.IncrementalSet;
import bcontractor.base.SetUtils;
import bcontractor.builder.Builder;
import bcontractor.builders.BuilderHelper;
import bcontractor.propositional.PropositionalSentence;

/**
 * 
 * Builder for knowledge bases bases
 * 
 * @author lundberg
 * 
 */
public class KnowledgeBaseBuilder<S extends Sentence<S>> implements Builder<SentenceSet<S>> {

    private IncrementalSet<S> sentences;

    /**
     * Construtor
     */
    public KnowledgeBaseBuilder() {
        this.sentences = IncrementalSet.aSet();
    }

    public static KnowledgeBaseBuilder<PropositionalSentence> aKnowledgeBase() {
        return new KnowledgeBaseBuilder<PropositionalSentence>();
    }

    @Override
    public SentenceSet<S> build() {
        return SetUtils.<S> emptySentenceSet().with(this.sentences.build());
    }

    public KnowledgeBaseBuilder<S> with(S sentence) {
        return BuilderHelper.copyWith(this, "sentences", this.sentences.with(sentence));
    }

    public KnowledgeBaseBuilder<S> with(SentenceSet<S> sentences) {
        return this.with(sentences.asSet());
    }

    public KnowledgeBaseBuilder<S> with(Collection<? extends S> sentences) {
        return BuilderHelper.copyWith(this, "sentences", this.sentences.with(sentences));
    }
}
